package com.skystar.commons.exception;

import org.apache.commons.lang3.StringUtils;

import com.skystar.commons.hmenum.ResultCodeEnum;

/**
 * @类名: HMExcetion
 * @描述: TODO
 * @作者: zfh
 * @时间: 2016-1-21 下午4:38:10
 */
public class BaseExcetion extends RuntimeException {

	/**
	 * @属性名: serialVersionUID
	 * @属性类型: long
	 * @描述: TODO
	 */
	private static final long serialVersionUID = -7036915404922221144L;

	private int errorCode;

	protected Throwable cause;

	protected BaseExcetion(String message) {
		super(message);
	}

	protected BaseExcetion(ResultCodeEnum codeEnum) {
		super(codeEnum.getMsg());
		this.errorCode = codeEnum.getCode();
	}

	protected BaseExcetion(int code) {
		super(ResultCodeEnum.getCodeEnum(code).getMsg());
		this.errorCode = code;
	}

	protected BaseExcetion(int code, String message) {
		super(StringUtils.isEmpty(message) ? ResultCodeEnum.getCodeEnum(code).getMsg() : message);
		this.errorCode = code;
	}

	protected BaseExcetion(int code, Throwable cause) {
		super(ResultCodeEnum.getCodeEnum(code).getMsg(), cause);
		this.cause = cause;
		this.errorCode = code;
	}

	protected BaseExcetion(ResultCodeEnum codeEnum, Throwable cause) {
		super(codeEnum.getMsg(), cause);
		this.cause = cause;
		this.errorCode = codeEnum.getCode();
	}

	protected BaseExcetion(ResultCodeEnum codeEnum, String message, Throwable cause) {
		super(StringUtils.isEmpty(message) ? codeEnum.getMsg() : message, cause);
		this.cause = cause;
		this.errorCode = codeEnum.getCode();
	}

	public BaseExcetion(int errorCode, String message, Throwable cause) {
		super(StringUtils.isEmpty(message) ? ResultCodeEnum.getCodeEnum(errorCode).getMsg() : message, cause);
		this.cause = cause;
		this.errorCode = errorCode;
	}

	protected BaseExcetion(BaseExcetion e) {
		super(e);
		this.cause = e.getCause();
		this.errorCode = e.getErrorCode();
	}

	protected BaseExcetion(ResultCodeEnum codeEnum, String message) {
		super(message);
		this.errorCode = codeEnum.getCode();
	}

	public Throwable getCause() {
		return cause;
	}

	public int getErrorCode() {
		return errorCode;
	}

}
